import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { configuration } from "../../../config/config";
import { MicroserviceOptions, Transport } from "@nestjs/microservices";
import { LogService } from "@app/log";

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { bufferLogs: true });
  app.enableCors();
  const logger = app.get(LogService);
  logger.log(`system 读取的配置内容为：${JSON.stringify(configuration.systemServer)}`)

  await Promise.all([
    app.listen(configuration.systemServer.http_port), // 启动 HTTP 服务
    app.connectMicroservice<MicroserviceOptions>({
      transport: Transport.NATS,
      options: {
        servers: configuration.natsServer,
      },
    }),
  ]);

  // 启动所有微服务
  await app.startAllMicroservices();
  logger.log(
    "SystemServer is running on http port " +
      configuration.systemServer.http_port + '   and nats client start'
  );
}

bootstrap();
